package com.oocl.action;

import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import com.oocl.entity.Customer;
import com.oocl.service.CustomerService;
import com.oocl.service.impl.CustomerServiceImpl;


public class Login extends HttpServlet {
	private static final long serialVersionUID = 1L;
	private CustomerService customerService = new CustomerServiceImpl();

	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		String account = request.getParameter("account");
		String password = request.getParameter("password");
		Customer customer = null;
		if( (!account.equals(""))&&(!password.equals("")) ){
			customer = customerService.login(account, password);
			if (customer!=null) {
				HttpSession session = request.getSession();
				session.setAttribute("uname", customer.getUname());		
				response.sendRedirect("Home");
			}else{
				request.getRequestDispatcher("index.jsp");
			}
		}else{
			request.getRequestDispatcher("index.jsp");
		}
		
	}

}
